package com.ymatou.iapi.productmanager.testcase;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.beans.factory.annotation.Autowired;

import com.ymatou.iapi.productmanager.parameter.GetProductSeatUseNumBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.GetProductSeatUseNumCall;
import com.ymt.core.tool.Logger;
import com.ymt.database.MyBatisUtil;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.mapping.YmtProductsIMapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.EnvSetup;
/**
*获取买手已使用坑位数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetProductSeatUseNum{
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static GetProductSeatUseNumBean getproductseatusenumBean = new GetProductSeatUseNumBean();
	private static GetProductSeatUseNumCall getproductseatusenumCall = new GetProductSeatUseNumCall();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取买手已使用坑位数");
	}

	@Before
	public void caseUp() {
		getproductseatusenumBean=new GetProductSeatUseNumBean();
		getproductseatusenumCall=new GetProductSeatUseNumCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getproductseatusenumCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductSeatUseNum_001() {
		Logger.start(true,"获取买手已使用坑位数");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			getproductseatusenumBean.setProductId(productId);
			getproductseatusenumBean.setSellerId(sellerId);
			getproductseatusenumCall.setData(getproductseatusenumBean);
			getproductseatusenumCall.callService();			
			int useNum = getproductseatusenumCall.getJsonObject().get("Data").getAsJsonObject().get("UseNum").getAsInt();
			Integer productSeatNum = new YmtProductsIWapper().getProductSeatNum(productId, sellerId);
			Logger.verifyEquals("200", getproductseatusenumCall.getString("Code"), "验证Code");
			Logger.verifyEquals(useNum, productSeatNum, "验证UseNum");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}